package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.resource.date.DateUtils;
import com.itheima.health.service.BusinessService;
import com.itheima.health.service.UserService;
import com.itheima.mapper.MemberMapper;
import com.itheima.mapper.OrderMapper;
import com.itheima.mapper.UserMapper;
import com.itheima.pojo.Permission;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;


@Service
@Transactional
public class BusinessServiceImpl  implements BusinessService {

    @Autowired
    private MemberMapper memberMapper;

    @Autowired
    private OrderMapper orderMapper;


    @Override
    public Map getBusinessData() {

        //   1. Map  map
        // 2   当天 日期     本周第一天  和 最后一天    本月的第一天 和最后一天
        Map  map = new HashMap();
        //  当天日期
        Date to = DateUtils.getToday();
        String  today = DateUtils.parseDate2String(to,"yyyy-MM-dd");

        String  thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday(),"yyyy-MM-dd");
        String  thisWeekSunday = DateUtils.parseDate2String(DateUtils.getSundayOfThisWeek(),"yyyy-MM-dd");

        String firstDayOfMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4CurrentMonth(),"yyyy-MM-dd");
        String  lastDayOfMonth =DateUtils.parseDate2String(DateUtils.getLastDayOfMonth(new Date()),"yyyy-MM-dd");

   //   会员数据
       int  todayNewMemberCount =  memberMapper.getTodayNewMember(today);
       int  thisWeekNewMemberCount  = memberMapper.getThisWeekNewMember(thisWeekMonday,thisWeekSunday);
       int totalMember = memberMapper.gettotalMember();
       int thisMonthNewMember = memberMapper.getthisMonthNewMember(firstDayOfMonth,lastDayOfMonth);

       // 预约数据
      int  todayOrderNumber = orderMapper.gettodayOrderNumber(today);
      int  todayVisitsNumber = orderMapper.gettodayVisitsNumber(today);
      int  thisWeekOrderNumber = orderMapper.getthisWeekOrderNumber(thisWeekMonday,thisWeekSunday);
      int  thisWeekVisitsNumber = orderMapper.getthisWeekVisitsNumber(thisWeekMonday,thisWeekSunday);
      int  thisMonthOrderNumber = orderMapper.getthisMonthOrderNumber(firstDayOfMonth,lastDayOfMonth);
      int  thisMonthVisitsNumber = orderMapper.getthisMonthVisitsNumber(firstDayOfMonth,lastDayOfMonth);
      //  热门套餐
        List<Map> mapList =  orderMapper.getHotSetmeal();

        map.put("reportDate",today);
        map.put("todayNewMember",todayNewMemberCount);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMemberCount);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",mapList);
        return map;
    }


}
